package com.xzt.demospringsecurity.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.io.File;
import java.io.IOException;

public class DemoGenerator {
    public static void main(String[] args) throws IOException {

        File file = new File("");
        String filePath = file.getCanonicalPath();

        FastAutoGenerator.create("jdbc:mysql://120.25.85.114:3306/studymall", "root", "root")
                .globalConfig(builder -> {
                    builder.author("xzt") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .dateType(DateType.TIME_PACK)
                            .commentDate("yyyy-MM-dd")
                            .outputDir(filePath + "/Demo-Spring-Security/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.xzt") // 设置父包名
                            .moduleName("demospringsecurity") // 设置父包模块名
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .xml("mapper.xml")
                            .controller("controller")
                            .other("other");
                })
                .strategyConfig(builder -> {
                    builder.enableSkipView()
                            .disableSqlFilter()
                            .addFieldSuffix("_flag")
                            .addTablePrefix("t_", "c_")
                            .entityBuilder().enableLombok()
                            .entityBuilder().naming(NamingStrategy.underline_to_camel)
                            .entityBuilder().columnNaming(NamingStrategy.underline_to_camel);
                })
                .templateEngine(new FreemarkerTemplateEngine())// 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }
}
